<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>骑自行车</title>
    <style>
        html,body{
            width: 100%;
            height: 100%;
        }
        *{margin: 0;padding: 0;}
        img{
            animation: run 6s 2 forwards paused;
        }
        p{
            text-align: center;
        }
        p button{
            width: 100px;
            margin: 0 20px;
        }
        @keyframes run{
            0%{
                transform: translate(0,0); 
            }
            100%{
                transform: translate(1200px,0); 
            }  
        }
    </style>
</head>
<body>
    <img src="./imgs/3/t0000.jpg" alt="">
    <p>
        <button id="start">开始</button>
        <button id="stop">停止</button>
    </p>
    <script>
        let img = document.querySelector('img');
        let startBtn = document.querySelector('#start');
        let stopBtn = document.querySelector('#stop');
        let timer;
        let n = 0;
        function run(){
            timer = setInterval(function(){
                n >= 10 && n < 12 ? img.src = `./imgs/3/t00${n}.jpg`: img.src = `./imgs/3/t000${n}.jpg`;
                n++;
                n === 12 ? n = 0 : n = n;
            },100); 
        }
        
        startBtn.addEventListener('click',function(){
            this.disabled = true;
            stopBtn.disabled = false;
            img.style.animationPlayState = 'running';
            run();
        })
        stopBtn.addEventListener('click',function(){
            this.disabled = true;
            startBtn.disabled = false;
            img.style.animationPlayState = 'paused';
            clearInterval(timer);
        })
    </script>
</body>
</html>